<template>
  <div class="message-container">
    <div class="header">
      <div class="back-btn">
        <i class="icon-back"></i>
      </div>
      <div class="title">全部消息</div>
    </div>
    <div class="message-list">
      <div class="message-item" v-for="(message, index) in messages" :key="index">
        <div class="avatar">
          <img :src="message.avatar" alt="Avatar">
        </div>
        <div class="content">
          <div class="name">{{ message.name }}</div>
          <div class="action">{{ message.action }} {{ message.date }}</div>
        </div>
        <div class="action-btn" v-if="message.actionBtn === 'follow'">
          <button @click="handleFollow(message)">回关</button>
        </div>
        <div class="action-btn" v-else-if="message.actionBtn ==='mutualFollow'">
          <span class="mutual-follow">互相关注</span>
        </div>
        <div class="action-btn" v-else-if="message.actionBtn">
          <img :src="'https://dbs-dbsww.oss-cn-beijing.aliyuncs.com/20201117115832_50dac.jpg'" alt="Image">
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      messages: [
        {
          avatar: 'https://example.com/avatar1.png',
          name: '梦回大唐',
          action: '关注了你',
          date: '09-14 12:00',
          actionBtn: 'follow'
        },
        {
          avatar: 'https://example.com/avatar2.png',
          name: '张三的猫',
          action: '关注了你',
          date: '09-14 12:00',
          actionBtn:'mutualFollow'
        },
        {
          avatar: 'https://example.com/avatar3.png',
          name: '阿秋',
          action: '赞了你的作品',
          date: '09-14 12:00',
          actionBtn: 'https://example.com/avatar2.png'
        }
      ]
    };
  },
  methods: {
    handleFollow(message) {
      // 这里可以添加实际的回关逻辑，比如发送请求到后端
      console.log(`回关 ${message.name}`);
    }
  }
};
</script>

<style scoped>
.message-container {
  padding: 20px;
  background-color: #f5f5f5;
}

.header {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}

.back-btn {
  width: 40px;
  height: 40px;
  background-color: #ccc;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-right: 10px;
}

.icon-back {
  font-size: 20px;
  color: #fff;
}

.title {
  flex: 1;
  font-size: 18px;
  font-weight: bold;
  text-align: center;
}

.message-list {
  background-color: #fff;
  border-radius: 10px;
  padding: 10px;
}

.message-item {
  display: flex;
  align-items: center;
  padding: 10px;
  border-bottom: 1px solid #eee;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  margin-right: 10px;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.content {
  flex: 1;
}

.name {
  font-size: 16px;
  font-weight: bold;
}

.action {
  font-size: 14px;
  color: #999;
  margin-top: 5px;
}

.action-btn {
  width: 70px;
  height: 40px;
  text-align: center;
}

.action-btn img{
  width: 40px;
  height: 40px;
  text-align: center;
  object-fit: cover
}

.action-btn button {
  padding: 5px 20px;
  border: none;
  border-radius: 15px;
  background-color: #1890ff;
  color: #fff;
  cursor: pointer;
}

.mutual-follow {
  padding: 5px 0px;
  border: 1px solid #ccc;
  border-radius: 5px;
  color: #999;
}
</style>